import random

word_list = ["PYTHON", "HANGMAN", "COMPUTER", "PROGRAM", "STRING"]
secret_word = random.choice(word_list)
guessed_word = ["_"] * len(secret_word)
attempts = 6  # The opportunity of guessing the letter
guessed_letters = []  # store the letter that the player guess

print("Welcome to Hangman!")
print("You have to guess the mystery word in 6 guesses or less.")
print("Here's what you have so far:", " ".join(guessed_word))

while attempts > 0 and "_" in guessed_word:
    guess = input("What letter would you like to guess: ").upper()

    # Check if the letter is in the word
    if guess in secret_word:
        print("Correct!!! You have", attempts, "guesses left.")
        for i in range(len(secret_word)):
            if secret_word[i] == guess:
                guessed_word[i] = guess
    else:
        attempts -= 1
        print("I'm sorry...", "You have", attempts, "guesses left.")

    # Show the status
    print("Here's what you have so far:", " ".join(guessed_word))

# game over
if "_" not in guessed_word:
    print("You have correctly guess the word", secret_word, "You win!")
else:
    print("You lose! The correct word is:", secret_word)
